#!/usr/bin/perl -w
use strict;
use HTTP::Proxy;
use HTTP::Proxy::HeaderFilter::simple;

# get the command-line parameters
my %args = (
   mime    		=> '*/*',
   logFileName	=> 'urls-log.txt',
);
{
    my $args = '(' . join( '|', keys %args ) . ')';
	
    for ( my $i = 0 ; $i < @ARGV ; $i += 2 ) {
        if ( $ARGV[$i] =~ /$args/o ) {
            if ( ref $args{$1} ) {
                push @{ $args{$1} }, $ARGV[ $i + 1 ];
            }
            else {
                $args{$1} = $ARGV[ $i + 1 ];
            }
            splice( @ARGV, $i, 2 );
            redo if $i < @ARGV;
        }
    }
}

# the headers we want to see
my $get_filter = HTTP::Proxy::HeaderFilter::simple->new(
    sub {
        my ( $self, $headers, $message ) = @_;
        my $req = $message->request;
		
		open OUT, '>>', $args{logFileName};	# appned
		print OUT $req->method, " ", $message->status_line, " ", $req->uri, "\n";
		close OUT;
    }
);

# create and start the proxy
my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->push_filter( response => $get_filter, mime => $args{mime} );
$proxy->start;
